﻿using HarmonyLib;
using RimWorld;
using System.Reflection;
using Verse;
using MonoMod.Utils;
using Androids;
using System;

namespace Miao.ArchotechFix
{
    public class ArchotechFix : Mod
    {
        public ArchotechFix(ModContentPack content) : base(content)
        {
            var harmony = new Harmony("ArchotechFix");
            //harmony.PatchAll(Assembly.GetExecutingAssembly());
            Assembly[] assemblys = AppDomain.CurrentDomain.GetAssemblies();


            ///必须这样写patch才能替换mod中的dll
            for (int i = 0; i < assemblys.Length; i++)
            {

                if (assemblys[i].GetName().Name == "Androids")
                {
                    harmony.PatchAll(assemblys[i]);
                    var patchType = typeof(ArchotechFixPathches);
                    var patchMethod = patchType.GetMethod(nameof(ArchotechFixPathches.ChangeRobotGender_Postfix), BindingFlags.Static | BindingFlags.Public);

                    Type type = typeof(DroidUtility);
                    //Type type = assemblys[i].GetType(nameof(DroidUtility));
                    MethodInfo method = type.GetMethod(nameof(DroidUtility.MakeDroidTemplate), BindingFlags.Static | BindingFlags.Public);
                    //MethodInfo t = Type.GetType(DroidUtility)
                    //var property = AccessTools.PropertyGetter(typeof(DroidUtility), nameof(DroidUtility.MakeDroidTemplate));
                    harmony.Patch(method, postfix: new HarmonyMethod(patchMethod));
                }
            }
            //harmony.Patch(AccessTools.PropertyGetter(typeof(DroidUtility), nameof(DroidUtility.MakeDroidTemplate)),postfix: new HarmonyMethod(type, nameof(ArchotechFixPathches.ChangeRobotGender_Postfix)));

        }



    }
}
